<extend name="common:commonNewerTemplate" />
<block name="main_content">
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a class="tip-bottom" href="index.html"
				data-original-title="Go to Home"><i class="icon-home"></i> 首页</a>
			<a href="#">经销商</a> <a class="current" href="#">经销商管理</a>
		</div>
	</div>
	<div class="container-fluid">
		<div class="row-fluid">
			<div class="span12">
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon"> <i class="icon-info-sign"></i>
						</span>
						<h5>搜索条件</h5>
					</div>
					<div class="widget-content nopadding">
						<form novalidate="novalidate" id="basic_validate"
							name="basic_validate" action="#" method="post"
							class="form-horizontal">
							<input type="hidden" name="dealer_channel" value="1"/>
							<input type="hidden" id="isBussiness" value="{$isBussiness}"/>
							<div class="control-group">
								<label class="control-label">经销商名称:</label>
								<div class="controls">
									<input type="text" id="dealer_name" name="dealer_name"/>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">经销商类型：</label>
								<div class="controls">
								<select id="dealer_type" name="dealer_type" style="width:220px;" >
									<option value="">--ALL--</option>
									<option value="1">一般纳税人</option>
									<option value="2">个体工商户</option>								
								</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">k3编码：</label>
								<div class="controls">
								<select id="k3_code" name="k3_code" style="width:220px;" >
									<option value="">--ALL--</option>
									<option value="1">存在</option>
									<option value="2">不存在</option>								
								</select>
								</div>
							</div>
							
							<div class="control-group">
								<label class="control-label">业务对接人:</label>
								<div class="controls">
									<input type="text" id="business_leader" name="business_leader"/>
								</div>
							 </div>
							 <div class="control-group">
								<label class="control-label">大区:</label>
								<div class="controls">
									<input type="text" id="area_name" name="area_name"/>
								</div>
							 </div>
							<div class="control-group">
								<label class="control-label">签约状态:</label>
								<div class="controls">
									<select id="sign_status" name="sign_status" style="width:220px;">
					                  <option value="">--ALL--</option>
					                  <option value="1">待签约</option>
					                  <option value="2">经销商待盖章</option>
					                  <option value="3">已签约</option>
					                </select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">状态:</label>
								<div class="controls">
									 <select id="status" name="status" style="width:220px;">
									 <option value="">--ALL--</option>
					                  <option value="1">待审核</option>
					                  <option value="2">已审核</option>
					                   <option value="3">审核拒绝</option>
					                </select>
								</div>
							</div>
							<div class="form-actions">
								<input id="btn_dealer_search" type="button" onclick="DealerInfoPage.searchclick('{$isBussiness}');"class="btn btn-success" value="搜索">
								<a target="_blank" href="/dealer/addDealer" style="background:red" class="btn btn-success" > 新增</a>
								
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	
	<div class="row-fluid">
      <div class="span12">
        <div class="widget-box">
          <div class="widget-title"> <span class="icon"> <i class="icon-th"></i> </span>
            <h5>搜索结果</h5>
             <span style="float:right;margin:3px;">
				<a href="#" class="btn btn-primary" id="exportXls">导出经销商列表xls</a>
			</span>
          </div>
          <div class="widget-content nopadding">
            <table id="search_result"  class="table table-bordered table-striped">
              <thead>
                <tr>
                 <th>经销商编号</th>
                  <th>经销商名称</th>
                  <th>经销商类型</th>
                  <th>金蝶唯一编码</th>
                  <th>经销商的默认折扣返点</th>
                  <th>经销商的后返点</th>
                  <th>业务对接人</th>
                  <th>大区</th>
                  <th>注册资金</th>
                  <th>法人代表</th>
                  <th>税号</th>
                  <th>财务联系人</th>
                  <th>发票寄送地址</th>
                  <th>签约状态</th>
                  <th>签约时间</th>
                  <th>状态</th>
                  <th>账户余额</th>
                  <th>账户余后返额</th>
                  <th>操作</th>
                </tr>
              </thead>
              <tbody>
              </tbody>
            </table>
          </div>
      </div>
      <div id="paging"
                         class="fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix">
                        <div class="dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi ui-buttonset-multi paging_full_numbers"
                             id="DataTables_Table_0_paginate">
                            <a page_index="1"
                               class="first ui-corner-tl ui-corner-bl fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_first">首页</a>
                            <a class="previous fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_previous">上页</a>
                            <span>共<span id="total_count">0</span>条 <span id="curr_page_index">0</span>/<span
                                    id="total_page">0</span></span>
                            <a class="next fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_next">下页</a>
                            <a class="last ui-corner-tr ui-corner-br fg-button ui-button ui-state-default" tabindex="0"
                               id="DataTables_Table_0_last">末页</a>
       			<span>
        			<span><input type="text" id="page_input" style="width:20px;" class="ui-state-default"></span>

        			<a class="fg-button ui-button ui-state-default" id="page_jump" tabindex="0">跳转</a>
       			</span>
                        </div>
       </div>
    </div>
  </div>
</div>
</div>
</block>

<block name="js_content">
<script>
DealerInfoPage = {
		
		
		'searchclick':function(index){
			
			if(index ==1){
				
				
				 DealerInfoPage.SaleSearch(1);
			}else{
							
				 DealerInfoPage.Search(1);
			}
			
			
			
		},
		
		'BindEvent': function(){
			/* $('#btn_dealer_search').bind('click', function(){
				
				 
				 var page_index = 1;
				 DealerInfoPage.Search(page_index);
			}); */
			
			
			
			$('#exportXls').on('click',function(){
				
				 var export_url = '/dealer/shipDealerInfoExcel?' + $("#basic_validate").serialize();
                 window.open(export_url);
				
				
			});

			$('#page_jump').bind('click', function(){
				
				 var page_index = $('#page_input').val();
				 var total_page = $('#total_page').text();
				
				 var curr_page = $('#curr_page_index').text();
				 
					
				 if (page_index == ''||page_index == undefined||page_index == null) {
	                    page_index = curr_page;
	                }
				 
				 if(parseInt(page_index) <= 0 || parseInt(page_index) > parseInt(total_page)  ){
					 page_index =1;
				 }
				 
				 
				 var isBussiness = $('#isBussiness').val();				 
				 if(isBussiness ==1){
											
					 DealerInfoPage.SaleSearch(page_index);
				}else{
								
					 DealerInfoPage.Search(page_index);
				}
								
				
			});
			
			
            $(".first,.previous,.last,.next").bind('click', function () {
                if ($(this).hasClass('ui-state-disabled')) {
                    return false;
                }

                var page_index = $(this).attr('page_index');
                if (page_index == undefined) {
                    page_index = 1;
                }
                var isBussiness = $('#isBussiness').val();				 
				
                if(isBussiness ==1){
											
					 DealerInfoPage.SaleSearch(page_index);
				}else{
								
					 DealerInfoPage.Search(page_index);
				}
							
            });
		},
		
   
		'Search': function (page_index) {
            var condition = $("#basic_validate").serialize();
            condition += "&pageSize=20&index="+page_index;

            $.ajax({
                type: 'post',
                url: '/AjaxService/center/dealer/queryDealerByPara',
                data: condition,
                dataType: 'json',
                async: false,
                success: function (data) {
                	DealerInfoPage.BindTable(data.Result, page_index);
                	DealerInfoPage.SetPageIndex(data.Result.totalPage, data.Result.totalCount, page_index);


                },
                error: function (e, err_name, err_text) {
                    alert(err_text);
                }
            });

        },
        
        'SaleSearch': function (page_index) {
            var condition = $("#basic_validate").serialize();
            condition += "&pageSize=20&index="+page_index;

            $.ajax({
                type: 'post',
                url: '/AjaxService/center/sale/querydealerbysaleandpara',
                data: condition,
                dataType: 'json',
                async: false,
                success: function (data) {
                	DealerInfoPage.BindTable(data.Result, page_index);
                	DealerInfoPage.SetPageIndex(data.Result.totalPage, data.Result.totalCount, page_index);


                },
                error: function (e, err_name, err_text) {
                    alert(err_text);
                }
            });

        },
        
		'BindTable': function(result,page_index){
			lst_dealer = result.datas;
			if(lst_dealer.length == 0){				
				$('#search_result tbody').html('');
				var msg ="<tr><td colspan='15' style='text-align:center'>暂无数据!</td></tr>";				
				$('#search_result tbody').append(msg);	
				return;							
			};
			var html = '';
			for(var index in lst_dealer){
				var dealer_en = lst_dealer[index];
				var tr_html = "<tr>";
				tr_html += "<td>" + dealer_en.dealer_id+"</td>";
				tr_html += "<td>" + dealer_en.dealer_name+"</td>";
				tr_html += "<td>" + DealerInfoPage.ConvertDealerType(dealer_en.dealer_type)+"</td>";
				tr_html += "<td>" + dealer_en.k3_code + "</td>"
				tr_html += "<td>" + dealer_en.discount_rate + "</td>"
				tr_html += "<td>" + DealerInfoPage.ConvertStrNull(dealer_en.cash_back_rate) + "</td>"
				tr_html += "<td>" + dealer_en.business_leader + "</td>"
				tr_html += "<td>" + dealer_en.area_name + "</td>"
				tr_html += "<td>" + dealer_en.registered_capital+"</td>";
				tr_html += "<td>" + dealer_en.leal_person+"</td>";
				tr_html += "<td>" + dealer_en.tax_no + "</td>"
				tr_html += "<td>" + dealer_en.finance_leader + "</td>"
				tr_html += "<td>" + dealer_en.invoice_address + "</td>"
				tr_html += "<td>" + DealerInfoPage.ConvertSignStatus(dealer_en.sign_status)+"</td>";
				tr_html += "<td>" + DealerInfoPage.ConvertStrNull(dealer_en.sign_date)+"</td>";
				tr_html += "<td>" + DealerInfoPage.ConvertStatus(dealer_en.status) + "</td>"
				tr_html += "<td>" + DealerInfoPage.ConvertStrNull(dealer_en.amount) + "</td>"
				tr_html += "<td>" + DealerInfoPage.ConvertStrNull(dealer_en.cashback_amount) + "</td>";
				tr_html += "<td>"+"<a target='_blank' style='color:blue;' href='/dealer/detailDealer?dealer_id="+ dealer_en.dealer_id + "'>修改   </a>"+
						"<a target='_blank' style='color:blue;' href='/dealer/showDealer?dealer_id="+ dealer_en.dealer_id  + "'>详情  </a>"+
						"<a target='_blank' style='color:blue;' href='/address/listAddress?user_id="+ dealer_en.user_id + "'>添加客戶地址 </a>"+	
						"<a target='_blank' style='color:blue;' href='/dealer/dealerAmountApply?dealer_id="+ dealer_en.dealer_id + "'>余额充值申请 </a>"+	
								"</td>"
				
				tr_html += "</tr>";
				html += tr_html;
			} 
			$('#search_result tbody').html('');
			$('#search_result tbody').append(html);
			 $('#search_result').attr('page_index', page_index);

		},
		
		'SetPageIndex': function (total_page, total_count, page_index) {
            $('#total_count').text(total_count);
            $('#total_page').text(total_page);
            $('#curr_page_index').text(page_index);
            page_index = parseInt(page_index);
            total_count =parseInt(total_count);
			
			if(total_page == 0){
				$('#paging .last').addClass('ui-state-disabled');
				$('#paging .next').addClass('ui-state-disabled');
				$('#paging .first').addClass('ui-state-disabled');
				$('#paging .previous').addClass('ui-state-disabled');
				return;
			}
            if (page_index == 1) {
                $('#paging .first').addClass('ui-state-disabled');
                $('#paging .previous').addClass('ui-state-disabled');
                $('#paging .first').attr('page_index', 1);
                $('#paging .previous').attr('page_index', 1);
            }
            else {
                $('#paging .first').removeClass('ui-state-disabled');
                $('#paging .previous').removeClass('ui-state-disabled');
                $('#paging .first').attr('page_index', 1);
                $('#paging .previous').attr('page_index', page_index - 1);
            }

            if (total_page == page_index) {
                $('#paging .last').addClass('ui-state-disabled');
                $('#paging .next').addClass('ui-state-disabled');
                $('#paging .last').attr('page_index', total_page);
                $('#paging .next').attr('page_index', total_page);
            }
            else {
                $('#paging .last').removeClass('ui-state-disabled');
                $('#paging .next').removeClass('ui-state-disabled');
                $('#paging .last').attr('page_index', total_page);
                $('#paging .next').attr('page_index', page_index + 1);
            }

        },

		'ConvertStrNull':function(obj){
			
			if(obj == null){
				return '';
			}
			else{
				return obj;
			}
		},
		'ConvertSignStatus':function(obj){
			if(obj == '1'){
				return '待签约';
			}else if(obj =='2'){
				return '经销商待盖章';
			}else if(obj =='3'){
				return '已签约';
			}
		} ,		
		'ConvertStatus':function(obj){
			if(obj == '1'){
				return '待审核';
			}else if(obj =='2'){
				return '已审核';
			}else if(obj =='3'){
				return '审核拒绝';
			}
		} ,		
		
		'ConvertDealerType':function(obj){
			if(obj == '1'){
				return '一般纳税人';
			}else if(obj =='2'){
				return '个体工商户';
			}
		} ,		
		
};


$(document).ready(function(){
	DealerInfoPage.BindEvent();
});


</script>
</block>